<!DOCTYPE html>
<html lang="en" th:with="title='保存文章',active='publish'" xmlns:th="http://www.thymeleaf.org">
<header th:replace="admin/header::headerFragment(${title},${active})"></header>
<link rel="stylesheet" th:href="@{/admin/plugins/tagsinput/jquery.tagsinput.css}"/>
<link rel="stylesheet" th:href="@{/admin/plugins/select2.dist.css/select2-bootstrap.css}"/>
<link rel="stylesheet" th:href="@{/admin/plugins/toggles/toggles.css}"/>

<link href="//cdn.bootcss.com/multi-select/0.9.12/css/multi-select.css" rel="stylesheet"/>
<link href="//cdn.bootcss.com/select2/3.4.8/select2.min.css" rel="stylesheet"/>
<link rel="stylesheet" th:href="@{/admin/plugins/md/css/style.css}"/>
<!-- editor.md -->
<link rel="stylesheet" th:href="@{/admin/editormd/css/editormd.css}"/>
<style>
    #tags_tagsinput {
        background-color: #fafafa;
        border: 1px solid #eeeeee;
    }

    #tags_addTag input {
        width: 100%;
    }

    #tags_addTag {
        margin-top: -5px;
    }
</style>
<body class="fixed-left">
<div id="wrapper">
    <div th:replace="admin/header::header-body"></div>
    <div class="content-page">
        <div class="content">
            <div class="container">
                <div class="row">
                    <div class="col-sm-12">
                        <h4 class="page-title">
                            <th:block th:if="${null != contents}">
                                编辑文章
                            </th:block>
                            <th:block th:unless="${null != contents}">
                                发布文章
                            </th:block>
                        </h4>
                    </div>
                    <div class="col-md-12">
                        <form id="articleForm" novalidate="novalidate" role="form">
                            <input id="categories" name="categories" type="hidden"/> <input id="type" name="type" type="hidden"/>
                            <input id="cid" name="cid" th:value="${contents!=null and contents.id!=null}?${contents.id}: ''" type="hidden"/>
                            <input id="status" name="status" th:value="${contents!=null and contents.status !=null}?${contents.status}: 'publish'" type="hidden"/>
                            <input id="allow_comment" name="allowComment" th:value="${contents!=null and contents.allowComment !=null}?${contents.allowComment}: true" type="hidden"/>
                            <input id="allow_ping" name="allowPing" th:value="${contents!=null and contents.allowPing !=null}?${contents.allowPing}: true" type="hidden"/>
                            <input id="allow_feed" name="allowFeed" th:value="${contents!=null and contents.allowFeed !=null}?${contents.allowFeed}: true" type="hidden"/>
                            <input id="content-editor" name="content" type="hidden"/>

                            <div class="form-group col-md-6" style="padding: 0 10px 0 0;">
                                <input aria-required="true" class="form-control" name="title" placeholder="请输入文章标题（必须）" required="required" th:value="${contents!=null and contents.title!=null }?${contents.title}: ''" type="text"/>
                            </div>

                            <div class="form-group col-md-6" style="padding: 0 0 0 10px;">
                                <select class="select2 form-control" data-placeholder="请选择文章类型.." id="multiple-type">
                                    <th:block th:if="${null == contents}">
                                        <option selected="selected" value="post">默认博文</option>
                                        <option value="photo">作品</option>
                                    </th:block>
                                    <th:block th:unless="${null == contents}">
                                        <option th:selected="${null != contents and contents.type=='post'} ? true : false" value="post">
                                            默认博文
                                        </option>
                                        <option th:selected="${null != contents and contents.type=='photo'} ? true : false" value="photo">
                                            作品
                                        </option>
                                    </th:block>
                                </select>
                            </div>

                            <div class="form-group col-md-6" style="padding: 0 10px 0 0;">
                                <!-- 如果是作品类，那么暂时不允许使用标签 -->
                                <input class="form-control" id="tags" name="tags" placeholder="请填写文章标签" th:value="${contents!=null and contents.tags !=null}?${contents.tags}: ''" type="text"/>
                            </div>
                            <div class="form-group col-md-6">
                                <select class="select2 form-control" data-placeholder="请选择分类..." id="multiple-sel" multiple="multiple">
                                    <th:block th:if="${null == categories}">
                                        <option selected="selected" value="默认分类">默认分类</option>
                                    </th:block>
                                    <th:block th:unless="${null == categories}">
                                        <th:block th:each="c : ${categories}">
                                            <option th:selected="${null !=contents and adminCommons.exist_cat(c, contents.categories)}?true:false" th:text="${c.name}" th:value="${c.name}"></option>
                                        </th:block>
                                    </th:block>
                                </select>
                            </div>

                            <div class="clearfix"></div>
                            <div id="my-editormd">
                                <textarea class="markdown-textarea" id="my-text" name="my-text" style="display:none;" th:utext="${contents!=null and contents.content !=null}?${contents.content}: ''"></textarea>
                                <!-- 注意：name属性的值-->
                                <textarea id="text" name="text" style="display:none;"></textarea>
                            </div>
                            <!--<div class="form-group">-->
                            <!--<textarea style="height: 450px" autocomplete="off" id="text" name="text"-->
                            <!--class="markdown-textarea"-->
                            <!--th:utext="${contents!=null and contents.content !=null}?${contents.content}: ''"></textarea>-->
                            <!--</div>-->

                            <div class="form-group col-md-3 col-sm-4" id="comment-div">
                                <label class="col-sm-4">开启评论</label>
                                <div class="col-sm-8">
                                    <div onclick="allow_comment(this);" th:class="${contents!=null and contents.allowComment!=null }?'toggle toggle-success allow-'+${contents.allowComment}:'toggle toggle-success allow-true'"></div>
                                </div>
                            </div>

                            <!--<div class="form-group col-md-3 col-sm-4">-->
                            <!--<label class="col-sm-4">允许Ping</label>-->
                            <!--<div class="col-sm-8">-->
                            <!--<div th:class="${contents!=null and contents.allowPing !=null}?'toggle toggle-success allow-'+${contents.allowPing}:'toggle toggle-success allow-true'"-->
                            <!--onclick="allow_ping(this);"></div>-->
                            <!--</div>-->
                            <!--</div>-->

                            <!--<div class="form-group col-md-3 col-sm-4">-->
                            <!--<label class="col-sm-4">允许订阅</label>-->
                            <!--<div class="col-sm-8">-->
                            <!--<div th:class="${contents!=null and  contents.allowFeed !=null}?'toggle toggle-success allow-'+${contents.allowFeed}: 'toggle toggle-success allow-true'"-->
                            <!--onclick="allow_feed(this);"></div>-->
                            <!--</div>-->
                            <!--</div>-->

                            <div class="clearfix"></div>

                            <div class="text-right">
                                <a class="btn btn-default waves-effect waves-light" th:href="@{/admin/article}">返回列表</a>
                                <button class="btn btn-primary waves-effect waves-light" onclick="subArticle('publish');" type="button">
                                    发布文章
                                </button>
                                <button class="btn btn-warning waves-effect waves-light" onclick="subArticle('draft');" type="button">
                                    存为草稿
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
                <div th:replace="admin/footer :: footer-content"></div>
            </div>
        </div>
    </div>
</div>
<div th:replace="admin/footer :: footer"></div>
<script type="text/javascript">
    $(function () {
        editormd("my-editormd", {//注意1：这里的就是上面的DIV的id属性值
            width: "90%",
            height: 640,
            syncScrolling: "single",
            path: "/admin/editormd/lib/",//注意2：你的路径
            saveHTMLToTextarea: true,//注意3：这个配置，方便post提交表单
            /**上传图片相关配置如下*/
            imageUpload: true,
            imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"], //图片上传格式
            imageUploadURL: "/admin/attach/uploadfile",
            onload: function (obj) { //上传成功之后的回调
            }
        });
    });

</script>
<script th:src="@{/admin/plugins/tagsinput/jquery.tagsinput.min.js}"></script>
<script th:src="@{/admin/plugins/jquery-multi-select/jquery.quicksearch.js}"></script>

<!-- editor.md -->
<script th:src="@{/admin/editormd/src/editormd.js}"></script>


<!--<script th:src="@{/admin/plugins/md/js/jquery.scrollto.js}"></script>-->
<!--<script th:src="@{/admin/plugins/md/js/pagedown.js}"></script>-->
<!--<script th:src="@{/admin/plugins/md/js/pagedown-extra.js}"></script>-->
<!--<script th:src="@{/admin/plugins/md/js/diff.js}"></script>-->
<!--<script th:src="@{/admin/plugins/md/js/md.js}"></script>-->

<script th:src="@{//cdn.bootcss.com/multi-select/0.9.12/js/jquery.multi-select.min.js}"></script>
<script th:src="@{//cdn.bootcss.com/select2/3.4.8/select2.min.js}"></script>
<script th:src="@{//cdn.bootcss.com/jquery-toggles/2.0.4/toggles.min.js}"></script>
<script th:src="@{/admin/js/article.js}"></script>
</body>
</html>